<template>
  <div class="container">
    <!-- 基础题库 查看弹框 -->
    <el-dialog title="题目预览" :visible="showPreviewDialog" width="47%" @close="handleClose">
      <el-row  style="margin:10px 0">
        <el-col :span="6">【题型】：{{formatQuestionType ()}}</el-col>
        <el-col :span="6">【编号】：{{previewData?.id}}</el-col>
        <el-col :span="6">【难度】：{{formatDifficulty()}}</el-col>
        <el-col :span="6">【标签】：{{previewData?.tags}}</el-col>
      </el-row>
      <el-row style="margin:19px 0">
        <el-col :span="6">【学科】：{{previewData?.subjectName}}</el-col>
        <el-col :span="6">【目录】：{{previewData?.directoryName}}</el-col>
        <el-col :span="6">【方向】：{{previewData?.direction}}</el-col>
      </el-row>
      <hr>
      <span>【题干】：</span>
         <span v-html="previewData.question"></span>
         <p v-if="previewData.questionType!=='3'">多选题 选项：（以下选中的选项为正确答案）</p>
         <el-row v-for="item in previewData.options" :key="item.id" >
          <p style="margin:0px 0px 10px 0px;display:flex;align-items: center;">
            <!-- 多选 -->
            <el-checkbox :value="item.isRight===1? true:false"  v-if="previewData.questionType==='2'" >{{item.title}}</el-checkbox>
            <!-- 单选 -->
            <el-radio-group    :value="isRight"  v-else-if="previewData.questionType==='1'" >
                    <el-radio   :label="item.isRight">{{item.title}}</el-radio>
            </el-radio-group>
            <!-- 图片 -->
            <img v-if="item.img" style="margin-left:30px" height="120" :src="item.img" alt="">
          </p>

         </el-row>
      <hr>
          <span>【参考答案】：<el-button type="danger" size="small" @click="isVideo=true">视频答案预览</el-button></span><br>
          <video v-if="isVideo" controls :src="previewData.videoURL" width="400px" height="300px"></video>
      <hr>
        <div>【答案解析】：
          <span style="display: inline-block"
           v-html="previewData.answer"></span>
        </div>
      <hr>
        <span>【题目备注】：{{previewData.remarks}}</span>
      <span slot="footer" class="dialog-footer" style="background:red">
        <el-button
        class="lihuhuhu"
          type="primary"
          @click="handleClose"
          >关闭</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { questionType, difficulty } from '@/api/hmmm/constants'
export default {
  components: {
  },
  props: {
    // 弹框状态值
    showPreviewDialog: {
      type: Boolean,
      default: false
    },
    // 数据
    previewData: {
      type: Object,
      default: () => {}
    }
  },
  computed: {
    isRight () {
      return this.previewData.options?.find(item => item.isRight === 1).isRight
    }
  },
  data () {
    return {
      isVideo: false // video隐藏
    }
  },
  methods: {
    // 关闭弹框
    handleClose () {
      this.isVideo = false
      this.$emit('update:showPreviewDialog', false)
    },
    // 题型
    formatQuestionType () {
      const questionTypeObj = questionType.find(item => item.value === this.previewData?.questionType)
      return questionTypeObj?.label ? questionTypeObj?.label : '未知'
    },
    // 难度
    formatDifficulty () {
      const difficultyObj = difficulty.find(item => item.value === this.previewData?.difficulty)
      return difficultyObj?.label ? difficultyObj.label : '未知'
    }
  }
}
</script>

<style scoped lang='scss'>
.el-dialog__footer {
.lihuhuhu {
  position: absolute;
  right: 20px;
  bottom: 20px;
}
}

</style>
